package br.com.tiaspider.services.listener;

import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.util.StringUtils;

import br.com.tiaspider.services.im.GtalkService;

public class GtalkPacketListener implements PacketListener{

	//private XMPPConnection connection;
	private GtalkService gtalk;
	
	public GtalkPacketListener( GtalkService gtalk ) {
		//connection = gtalk.getConnection();
		this.gtalk = gtalk;
	}

	public void processPacket( Packet packet ) {
		Message message = ( Message ) packet;
		String text = message.getBody();
		String from = StringUtils.parseBareAddress( message.getFrom() );
		
		System.out.println( "Message received (" + from +"): " +  text );
		
		if( text != null ){	

			gtalk.executeCommand( text , from );
			
		}
		
	}
	
}